import json

data = {'name': '蔡徐坤', 'age': 25, 'gender': '男', 'job': 'singer'}

json_data = json.dumps(data, ensure_ascii=False, indent=4)  # 正常显示中文 缩进4字符
print('字典转json:', json_data)

dic = json.loads(json_data)
print('json转字典:', dic)

with open('jsonData.txt', 'r', encoding='utf-8') as f:
    my_dict = json.load(f)
    print(my_dict)

my_json = {"name": "B站", "url": "www.bilibili.com"}

with open('jsonData.txt', 'a', encoding='utf-8') as f:
    json.dump(my_json, f, ensure_ascii=False, indent=4)
